﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using Candy.ViewModel;

namespace Candy
{
    public partial class JobManagerPage : Page
    {
        JobManagerViewModel _viewModel;
        public JobManagerPage()
        {
            InitializeComponent();
            _viewModel = (JobManagerViewModel)DataContext;
            this.NavigationCacheMode = System.Windows.Navigation.NavigationCacheMode.Required;
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
           // jobManager.Show();
            if (_viewModel.EnableAutoRefresh.CanExecute(null))
                _viewModel.EnableAutoRefresh.Execute(null);
        }

        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            base.OnNavigatedFrom(e);
            if (_viewModel.DisableAutoRefresh.CanExecute(null))
                _viewModel.DisableAutoRefresh.Execute(null);
        }



        //#region ExpanderLayouting
        //private double _lastFamilyWidth = 400;
        //private void OnExpand(object sender, RoutedEventArgs e)
        //{
        //    if (LayoutRoot != null)
        //    {
        //        LayoutRoot.ColumnDefinitions[0].Width = new GridLength(_lastFamilyWidth);
        //        Splitter.IsEnabled = true;
        //        Splitter.Visibility = Visibility.Visible;
        //    }
        //}

        //private void OnCollapsed(object sender, RoutedEventArgs e)
        //{
        //    if (LayoutRoot != null)
        //    {
        //        _lastFamilyWidth = LayoutRoot.ColumnDefinitions[0].Width.Value;
        //        LayoutRoot.ColumnDefinitions[0].Width = new GridLength(0, GridUnitType.Auto);
        //        Splitter.IsEnabled = false;
        //        Splitter.Visibility = Visibility.Collapsed;

        //    }

        //}
        //#endregion


 
        private void OnJobSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (ResultDataGrid.SelectedItem is JobViewModel)
                _viewModel.SelectedJob = ResultDataGrid.SelectedItem as JobViewModel;
        }

        private void OnJobSelected(object sender, RoutedPropertyChangedEventArgs<object> e)
        {
            _viewModel.SelectedJob = jobTree.SelectedItem as JobViewModel;
        }
    }
}
